package com.ukao.pad.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.pad.R;
import com.ukao.pad.bean.ProductBatchInBean;
import com.ukao.pad.utils.CheckUtils;

import java.util.List;

import static com.ukao.pad.R.id.isFinish;

/**
 * Created by ukaodev on 2017/7/19.
 * 记住来看
 */

public class StartFactoryAdapter extends CommonAdapter<ProductBatchInBean> {

    private boolean isleaveEnter;


    public StartFactoryAdapter(Context context, List<ProductBatchInBean> datas) {
        super(context, datas, R.layout.adapter_start_factory);
    }

    public StartFactoryAdapter(Context context, List<ProductBatchInBean> datas, boolean isleaveEnter) {
        super(context, datas, R.layout.adapter_lever_factory);
        this.isleaveEnter = isleaveEnter;
    }

    @Override
    public void convert(ViewHolder holder, ProductBatchInBean item) {


        ImageView checkBox = holder.getView(R.id.checkBox);
        TextView productName = holder.getView(R.id.productName);
        TextView scanCode = holder.getView(R.id.scanCode);
        TextView statusText = holder.getView(R.id.statusText);
        TextView bindCode = holder.getView(R.id.bindCode);
        productName.setText(item.getProductName());
        scanCode.setText(item.getScanCode());
        bindCode.setText(item.getBindCode());
        int state;
        if (isleaveEnter) {
            TextView storeName = holder.getView(R.id.store_name);
            storeName.setText(CheckUtils.isEmptyString(item.getStoreName()));
            statusText.setText(item.getFactoryStatusText());
            state = item.getFactoryStatus();
            if (item.isFinish()){
                checkBox.setVisibility(View.INVISIBLE);
            }



        } else {
            if (item.isOrder()) {
                statusText.setText(item.getIsFactoryStatus() == 1 ? "已核对" : "未核对");
            } else {
                statusText.setText(item.getStatusText());
            }

            state = item.isOrder() ? item.getIsFactoryStatus() : item.getStatus();
        }
        switch (state) {
            case 1:
                statusText.setTextColor(mContext.getResources().getColor(R.color.green));
                if (!isleaveEnter) checkBox.setVisibility(View.INVISIBLE);

                break;
            case 0:/*未核对*/
                if (!isleaveEnter) checkBox.setVisibility(View.VISIBLE);
                statusText.setTextColor(mContext.getResources().getColor(R.color.gray_font));
                break;
            case 2: /*已上报缺失*/
                if (!isleaveEnter) checkBox.setVisibility(View.INVISIBLE);
                statusText.setTextColor(mContext.getResources().getColor(R.color.normal_red));
                break;
        }

        if (item.isCheck()) {
            checkBox.setImageResource(R.drawable.check_box_check);
        } else {
            checkBox.setImageResource(R.drawable.check_box_normal);
        }

    }

}
